var $table;  
var selectionIds = [];  //保存选中ids  
var busCompanyField = dataObject.busCompanyField;
var singleStatus;
var toolbar = "toolbar_dialog";
var isSelected = true;
$(function () {
	  var columns =[
                       {field: 'state', checkbox: true},
                       {field: 'companyId' , title: busCompanyField.companyId, sortName:'COMPANY_ID' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'companyName' , title: busCompanyField.companyName, sortName:'COMPANY_NAME' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'status' , title: busCompanyField.status, formatter: 'statusFormatter', sortName:'STATUS' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'regionName' , title: busCompanyField.regionId, formatter: 'regionFormatter', sortName:'REGION_ID' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'createTime' , title: busCompanyField.createTime, sortName:'CREATE_TIME' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'userName' , title: busCompanyField.createBy, sortName:'CREATE_BY' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'action', title: pageData.action, formatter: '$table.actionFormatter', events: 'actionEvents', clickToSelect: false, width: 150, halign: 'center', align: 'center'}
                   ];
    $table = new BSTable("table", 'bus/buscompany/list', columns,"toolbar",510,'companyNo','COMPANY_NO','buscompany');
    var queryParams = function(params) {            
         return {
         	       page: params.pageNumber,
         	       limit: params.pageSize,
         	       sidx: params.sortName,
                   order: params.sortOrder,
                   status:vm.search.status,
                   companyId:vm.search.companyId,
                   companyName:vm.search.companyName,
              //查询字段
             };
     };
	$table.setQueryParams(queryParams);
    $table.init();



});

function regionFormatter(value,row){
    if(row.regionId){
        return '<a href="javascript:;" onclick="defaultActions.iframeDetail(\'详情\', \'../bus/busregion.html?detailId='+ row.regionId +'\',280);">'+value+'</a>';
    }
}

var actionUrl = {
	save:   $path+"/bus/buscompany/save",
	update: $path+"/bus/buscompany/info/",
	delete: $path+"/bus/buscompany/delete",
	audit:  $path+"/bus/buscompany/audit",
	copy: $path+"/bus/buscompany/audit"
};

var vm = new Vue({
	el:'#app',
	data:{
		showList: true,
		title: null,
        module:"busCompany",
        moduleId:"companyNo",
        active: 0,
		busCompany: {

		},

		search:{
            companyName:"",
		}
	},
	methods: {
        busRegionAssiot: function(){
				selectionIds=[];
				singleStatus = true;
				selectionIds.push(vm.busCompany.regionId);
				var fun = function(dialogRef) {
	                    var row=$.map($("#table_dialog").bootstrapTable('getSelections'),function(row){
	                        return row ;
			    	    });
						var id,regionName='';
						if(row.length > 0){
								for(var i=0;i<row.length;i++){
				    				id=row[i].id;
				    				regionName=row[i].regionName;
				    		}
						}
	                    vm.busCompany.regionId=id;
						vm.busCompany.regionName=regionName;
						$("input[name='regionId']").val(id).change();
	                    dialogRef.close();
			      };
	  	        defaultActions.assiot(busCompanyField.regionId, '../dialog/bus/busRegion_dialog.html', fun);
		},
        next:function() {
           if (vm.active++ > 2) this.active = 0;
        }
	},
    mounted:function () {
        $("#wizard").steps({autoFocus: true});
        $("#wizard").steps({autoFocus: true});
    }
});

/*表单校验 start*/
$('#defaultForm').bootstrapValidator({
    feedbackIcons: vail.feedbackIcons(),
    fields: {
               companyId: vail.REPEATREGEX("运营商编码",busCompanyField.companyId,"25",$path+"/bus/buscompany/checkExist","busCompany","companyNo","companyId","company_id",/^[A-Za-z0-9]+$/,"不能有中文和特殊符号"),
               companyName: vail.REPEATREGEX("运营商名称",busCompanyField.companyName,"25",$path+"/bus/buscompany/checkExist","busCompany","companyNo","companyName","company_name",/^[\S]*$/,"不能有空格"),
               regionId: vail.NOTNULL("关联区域",busCompanyField.regionId),
		    
    }
});
/*表单校验 end*/
